package com.matt.controller.web;

import com.matt.domain.TargetObject;
import com.matt.domain.course.CoursePlanTopic;
import com.matt.domain.course.CourseTopic;
import com.matt.foundation.constant.RequestConstant;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.foundation.query.CourseTopicQuery;
import com.matt.foundation.vo.course.CourseTopicPageVo;
import com.matt.service.CourseTopicService;
import com.matt.service.UploadService;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/8
 * *******************************
 */
@RestController
@RequestMapping("/web/course_topic")
public class WebCourseTopicController {

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private UploadService uploadService;

    @Autowired
    private CourseTopicService courseTopicService;

    @ApiOperation(value = "添加主题课程",httpMethod = "POST")
    @RequestMapping(value = "create")
    public StatusResponse createCourseTopic(@RequestHeader(RequestConstant.TICKET) String ticket, CourseTopic courseTopic, String month, String begin, String end) {
        CourseTopic topic = courseTopicService.create(courseTopic, month, begin, end, cache.getStaffId(ticket));
        return StatusResponse.success(topic);
    }

    @ApiOperation(value = "修改主题课程",httpMethod = "POST")
    @RequestMapping(value = "modify")
    public StatusResponse modifyCourseTopic(CourseTopic courseTopic, String month, String begin, String end) {
        CourseTopic topic = courseTopicService.modify(courseTopic, month, begin, end);
        return StatusResponse.success(topic);
    }

    @ApiOperation(value = "查询主题课程列表",httpMethod = "POST")
    @RequestMapping(value = "page")
    public StatusResponse page(CourseTopicQuery query) {
        Page<CourseTopicPageVo> voPage = courseTopicService.page(query);
        return StatusResponse.success(voPage);
    }

    @ApiOperation(value = "查看主题详情",httpMethod = "POST")
    @RequestMapping(value = "detail")
    public StatusResponse detail(String topicId) {
        CourseTopic courseTopic = courseTopicService.detail(topicId);
        return StatusResponse.success(courseTopic);
    }

    @ApiOperation(value = "主题课程下面所排课程",httpMethod = "POST")
    @RequestMapping(value = "course_plan_list")
    public StatusResponse coursePlanList(String topicId) {
        List<CoursePlanTopic> coursePlanNurseryList = courseTopicService.getCoursePlanList(topicId);
        return StatusResponse.success(coursePlanNurseryList);
    }

    @ApiOperation(value = "上传主题图片",httpMethod = "POST")
    @RequestMapping(value = "upload_img")
    public StatusResponse createCourseTopic(MultipartFile file) {
        String url = uploadService.uploadCourseTopicAdvise(file);
        return StatusResponse.success(url);
    }

    @ApiOperation(value = "获取所有适用对象（不包括全部",httpMethod = "POST")
    @RequestMapping(value = "target_object_list")
    public StatusResponse targetObjectList() {
        List<TargetObject> targetObjectList = courseTopicService.getTargetObject();
        if (targetObjectList.size()>0){
            targetObjectList.remove(0);
        }
        return StatusResponse.success(targetObjectList);
    }

    @ApiOperation(value = "获取所有适用对象（包括全部）",httpMethod = "POST")
    @RequestMapping(value = "target_object_all_list")
    public StatusResponse targetObjectAllList() {
        List<TargetObject> targetObjectList = courseTopicService.getTargetObject();
        return StatusResponse.success(targetObjectList);
    }
}
